﻿using ZYCommon;
using System;
using System.Drawing;

namespace TextEditor
{
    

    public class ImageTextAction : ImageEditAction
    {
        public bool Bold = false;
        public string FontName = "宋体";
        public float FontSize = 10f;
        public Color ForeColor = Color.Black;
        public bool Italic = false;
        public Rectangle Rect = Rectangle.Empty;
        public string Text = null;

        public override bool Execute(Graphics g, Rectangle ClipRect)
        {
            if ((this.Text != null) && (this.Text.Length > 0))
            {
                using (Font font = new Font(this.FontName, this.FontSize, DocumentView.GetFontStyle(this.Bold, this.Italic, false)))
                {
                    using (SolidBrush brush = new SolidBrush(this.ForeColor))
                    {
                        using (StringFormat format = new StringFormat())
                        {
                            format.Alignment = StringAlignment.Center;
                            format.LineAlignment = StringAlignment.Center;
                            g.DrawString(this.Text, font, brush, new RectangleF((float) this.myBounds.Left, (float) this.myBounds.Top, (float) this.myBounds.Width, (float) this.myBounds.Height), format);
                        }
                    }
                }
            }
            return true;
        }

        public override string ActionName
        {
            get
            {
                return "text";
            }
        }
    }
}

